OPC Studio User's Guide and Reference
Variable Data Type Considerations
Concepts > OPC Wizard Concepts > OPC Wizard Operation Model > Data Variable Configuration > Variable Data Type Considerations
In This Topic

The Variant OPC UA Data Type

In OPC UA, Variant is a built-in type that can hold any data type (an instance of any type derived from BaseDataType, which is at the root of the data type hierarchy). In its default state (without further configuration), every UADataVariable has its DataTypeId Property set to BaseDataType, indicating the use of the Variant built-in type. Such variables can therefore hold value of any OPC UA type.

Unless you have a specific need that requires the use of the Variant OPC UA data type, it is strongly recommended that you always set the data type of the variable to a more specific data type. The data type provides useful information to other OPC UA applications, and with the use of Variant, is is effectively lost.

Example: Installed Examples - Server Library - UAServerDemoLibrary

Data Types in Data Provision

Because the data type model in OPC UA is not identical with the .NET type model, you need to understand what the type correspondences are, and in some cases the OPC UA data types are represented by .NET types that differ from intuitive expectations. To learn about the representation of OPC UA data types in OPC Studio, see Data Types in OPC-UA.

Pull Data Provision Model

When you use the extension method for Data Variable Configuration, and provide a function that handles the Read request, OPC Wizard determines the OPC UA data type of the variable (and its value rank) from the .NET type of the function argument. For example, if you use the simplest ReadValueFunction method overload and simply pass it a function that returns System.Int32 type, the OPC UA data type (the DataTypeId Property of the data variable) will be automatically determined to be UADataTypeIds.Int32.

There are cases, however, when this automatic mechanism is not suitable; if so, you can still use the extension methods for data variable configuration, but you have to specify the desired data type in some additional ways. This happens e.g. when multiple OPC UA data types are mapped to a single .NET type (as per Data Types in OPC-UA article). In the example given above, OPC Wizard uses System.Int32 not only for OPC UA Int32 data type, but also for UInt16 (this is for it to be CLS-compliant and usable from languages like VB.NET; similarly with some other integer types). If you want your data variable be of OPC UA SByte, UInt16, UInt32 or UInt64 data type, you can do it similarly to the following example.

Example: Examples - Server OPC UA - Data variable UInt16 value, reading using a function

Also, in OPC UA, there is a ByteString type. According to newer OPC UA specifications, this type should be handled interchangeably with a single-dimensional array of Byte. When OPC Wizard methods encounter a .NET array of bytes, they prefer to choose the OPC UA ByteString data type for it, unless specified otherwise. The following example illustrates an implementation of a readable data variable with OPC UA data type ByteString.

Example: Examples - Server OPC UA - Data variable ByteString value, reading using a function

Push Data Provision Model

In the Push Data Provision Model, the concerns described above with the Pull Data Provision Model still apply. However, since in the configuration methods there is no function provided with an argument from which the data type can be automatically determine, you will end up specifying the data type yourself, typically by some overload of the ValueType Method.

Example: Examples - Server OPC UA - Implement variable reading on folder level, with an event

Data Types in Data Consumption

Because the data type model in OPC UA is not identical with the .NET type model, you need to understand what the type correspondences are, and in some cases the OPC UA data types are represented by .NET types that differ from intuitive expectations. To learn about the representation of OPC UA data types in OPC Studio, see Data Types in OPC-UA.

Push Data Consumption Model

When you use the extension method for Data Variable Configuration, and provide a function (or action) that handles the Write request, OPC Wizard determines the OPC UA data type of the variable (and its value rank) from the .NET type of the function (or action) argument. For example, if you use the simplest WriteValueAction method overload and simply pass it an action that takes System.Int32 argument, the OPC UA data type (the DataTypeId Property of the data variable) will be automatically determined to be UADataTypeIds.Int32.

There are cases, however, when this automatic mechanism is not suitable; if so, you can still use the extension methods for data variable configuration, but you have to specify the desired data type in some additional ways. This happens e.g. when multiple OPC UA data types are mapped to a single .NET type (as per Data Types in OPC-UA article). In the example given above, OPC Wizard uses System.Int32 not only for OPC UA Int32 data type, but also for UInt16 (this is for it to be CLS-compliant and usable from languages like VB.NET; similarly with some other integer types). If you want your data variable be of OPC UA SByte, UInt16, UInt32 or UInt64 data type, you can do it similarly to the following example.

Example: Examples - Server OPC UA - Implement UInt16 value writing using an action

Also, in OPC UA, there is a ByteString type. According to newer OPC UA specifications, this type should be handled interchangeably with a single-dimensional array of Byte. When OPC Wizard methods encounter a .NET array of bytes, they prefer to choose the OPC UA ByteString data type for it, unless specified otherwise. The following example illustrates an implementation of a  writable data variable with OPC UA data type ByteString.

Example: Examples - Server OPC UA - Implement ByteString value writing using an action

Pull Data Consumption Model

In the Pull Data Consumption Model, the concerns described above with the Push Data Consumption Model still apply. However, since in the configuration methods there is no function or action provided with an argument from which the data type can be automatically determine, you will end up specifying the data type yourself, typically by some overload of the ValueType Method.

Example: Examples - Server OPC UA - Implement variable writing on folder level, with an event

See Also

Examples - Server OPC Unified Architecture

Reference

Installed Examples - Server Library